package com.atguigu.tingshu.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: hsl
 * @CreateTime: 2025-02-25  18:19
 */
@Component
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                // 核心线程数
                Runtime.getRuntime().availableProcessors(),
                // 最大线程数
                Runtime.getRuntime().availableProcessors() * 2,
                // 线程存活时间
                60,
                // 时间单位
                TimeUnit.SECONDS,
                // 队列
                new LinkedBlockingQueue<>(1024),
                // 线程工厂
                Executors.defaultThreadFactory(),
                // 拒绝策略
               new ThreadPoolExecutor.AbortPolicy()
        );
}}
